<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px">
      <el-form-item label="发行状态" prop="issueType">
        <el-select v-model="queryParams.issueType" clearable placeholder="请选择发行状态" size="small">
          <el-option
            v-for="dict in issueTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="verifyType">
        <el-select v-model="queryParams.verifyType" clearable placeholder="请选择审核状态" size="small">
          <el-option
            v-for="dict in verifyTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="parseInt(dict.dictValue)"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="historyList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="发行人" prop="issuer" width="150">
        <template slot-scope="scope">
          <a href="#" style="color: #1c84c6" @click="handleQueryResume(scope.row.createById)"><span>{{
              scope.row.issuer
            }}</span></a>
        </template>
      </el-table-column>
      <el-table-column :formatter="issueTypeFormat" align="center" label="发行状态" prop="issueType"/>
      <el-table-column align="center" label="资金用途" prop="issueUse" width="300"/>
      <el-table-column align="center" label="发行数量" prop="issueNumber" width="100"/>
      <el-table-column align="center" label="分红承诺" prop="issueBonus" width="500"/>
      <el-table-column :formatter="verifyTypeFormat" align="center" label="审核状态" prop="verifyType"></el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.verifyType === 1"
                     v-hasPermi="['operate:issue:approval:edit']"
                     icon="el-icon-document-checked"
                     size="mini"
                     type="text"
                     @click="handleApproval(scope.row)"
          >审核
          </el-button>
          <el-button v-hasPermi="['operate:issue:approval:edit']"
                     icon="el-icon-folder-delete"
                     size="mini"
                     type="text"
                     @click="handleReport(scope.row)"
          >举报
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改发行历史对话框 -->
    <el-dialog :visible.sync="open" append-to-body title="审核" width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-descriptions column="1" title="发行信息">
          <el-descriptions-item label="发行状态">{{ issueTypeFormat(form) }}</el-descriptions-item>
          <el-descriptions-item label="资金用途">{{ form.issueUse }}</el-descriptions-item>
          <el-descriptions-item label="发行数量">{{ form.issueNumber }}</el-descriptions-item>
          <el-descriptions-item label="分红承诺">
            {{ form.issueBonus }}
          </el-descriptions-item>
        </el-descriptions>
        <div class="el-descriptions-title">
          审核信息
        </div>

        <el-form-item label="审核意见" prop="field101">
          <el-radio-group v-model="form.verifyType" size="medium">
            <el-radio v-for="(item, index) in auditOpinionOptions" :key="index" :disabled="item.disabled"
                      :label="item.value">{{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>

        <div class="margin-top">
          <el-form-item label="审核描述" prop="remark">
            <el-input v-model="form.remark" placeholder="请输入内容" type="textarea"/>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
        <el-button type="primary" @click="saveForm">保 存</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="reportOpen" append-to-body title="举报" width="800px">
      <el-form ref="formReport" :model="form" :rules="rules" label-width="80px">
        <div class="margin-top">
          <el-form-item label="举报内容" prop="remark">
            <el-input v-model="form.report" placeholder="请输入内容" type="textarea"/>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelReport">关 闭</el-button>
        <el-button type="primary" @click="saveReportForm">保 存</el-button>
      </div>
    </el-dialog>

    <ResumeDetail ref="editDialog"></ResumeDetail>
  </div>
</template>

<script>
import {listIssueApproval, getIssueApproval, approvalIssue, reportIssueHistory} from "@/api/operate/issueApprove";
import ResumeDetail from "@/views/publish/resume/detail"


export default {
  name: "IssueHistoryApproval",
  components: {ResumeDetail},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 发行历史表格数据
      historyList: [],
      // 弹出层标题
      title: "修改发行股票",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      reportOpen: false,
      // 发行状态字典
      issueTypeOptions: [],
      // 审核状态字典
      verifyTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        issueType: null,
        verifyType: 1,
        issueUse: null,
        issueNumber: null,
        issueBonus: null,
        deptId: null,
        createById: null,
        updateById: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        verifyType: [{
          required: true,
          message: '审核意见不能为空',
          trigger: 'change'
        }],
      },
      // 审核意见
      auditOpinionOptions: [{
        "label": "通过",
        "value": 2
      }, {
        "label": "驳回",
        "value": 3
      }],
    };
  },
  created() {
    this.getList();
    this.getDicts("issue_type").then(response => {
      this.issueTypeOptions = response.data;
    });
    this.getDicts("verify_type").then(response => {
      this.verifyTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询发行历史列表 */
    getList() {
      this.loading = true;
      listIssueApproval(this.queryParams).then(response => {
        this.historyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 发行状态字典翻译
    issueTypeFormat(row) {
      return this.selectDictLabel(this.issueTypeOptions, row.issueType);
    },
    // 审核状态字典翻译
    verifyTypeFormat(row) {
      return this.selectDictLabel(this.verifyTypeOptions, row.verifyType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 举报弹窗取消按钮
    cancelReport() {
      this.reportOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        issueType: null,
        issueUse: null,
        issueNumber: null,
        verifyType: 0,
        issueBonus: null,
        report: null,
        deptId: null,
        createBy: null,
        createById: null,
        createTime: null,
        updateBy: null,
        updateById: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 审核按钮操作 */
    handleApproval(row) {
      this.reset();
      const id = row.id || this.ids
      getIssueApproval(id).then(response => {
        this.form = response.data;
        this.open = true;
      });
    },
    /** 举报按钮操作 */
    handleReport(row) {
      this.reset();
      const id = row.id || this.ids
      getIssueApproval(id).then(response => {
        this.form = response.data;
        this.reportOpen = true;
      });
    },
    /** 保存按钮 */
    saveForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            approvalIssue(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 保存举报 */
    saveReportForm() {
      this.$refs["formReport"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            this.form.verifyType = 3;
            reportIssueHistory(this.form).then(response => {
              this.msgSuccess("举报成功");
              this.reportOpen = false;
              this.getList();
            });
          }
        }
      });
    },

    // 查看简历
    handleQueryResume(userId) {
      console.log(userId)
      this.$refs['editDialog'].open = true;
      this.$refs['editDialog'].init(userId);
      this.$refs['editDialog'].getStory(userId);
    }
  }
};
</script>

<style scoped>
.box-card {
  margin: 20px 0;
}

.el-descriptions-title {
  margin-top: 40px;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: bold;
}

.margin-top {
  margin-top: 20px;
}
</style>
